using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Data;
 using System.Data.SqlClient;
 using MinhTam.DataAccess.Web;
//───────────────────────────────────────────────────────────────────────────────────────
 namespace MinhTam.Objects
  { 
 public class USERS:  SQLConnectWeb { 
 public static string sTableName= "USERS"; 
   public string USERS_ID;
   public string USERS_NAME;
   public string USERS_PASS;
   public string FULL_NAME;
   public string ADDRESS;
   public string PHONE;
   public string USER_GROUP_ID;
   public string LAST_ACCESS;
   public string IS_CHANGE_PASS;
   #region DataColumn Name ;
 public static  string cl_USERS_ID="USERS_ID" ;
 public static  string cl_USERS_NAME="USERS_NAME" ;
 public static  string cl_USERS_PASS="USERS_PASS" ;
 public static  string cl_FULL_NAME="FULL_NAME" ;
 public static  string cl_ADDRESS="ADDRESS" ;
 public static  string cl_PHONE="PHONE" ;
 public static  string cl_USER_GROUP_ID="USER_GROUP_ID" ;
 public static  string cl_LAST_ACCESS="LAST_ACCESS" ;
 public static  string cl_IS_CHANGE_PASS="IS_CHANGE_PASS" ;
 #endregion;
//───────────────────────────────────────────────────────────────────────────────────────
       public USERS() {}
//───────────────────────────────────────────────────────────────────────────────────────
       public USERS(
         string sUSERS_ID,
         string sUSERS_NAME,
         string sUSERS_PASS,
         string sFULL_NAME,
         string sADDRESS,
         string sPHONE,
         string sUSER_GROUP_ID,
         string sLAST_ACCESS,
         string sIS_CHANGE_PASS){
         this.USERS_ID= sUSERS_ID;
         this.USERS_NAME= sUSERS_NAME;
         this.USERS_PASS= sUSERS_PASS;
         this.FULL_NAME= sFULL_NAME;
         this.ADDRESS= sADDRESS;
         this.PHONE= sPHONE;
         this.USER_GROUP_ID= sUSER_GROUP_ID;
         this.LAST_ACCESS= sLAST_ACCESS;
         this.IS_CHANGE_PASS= sIS_CHANGE_PASS;
}
//───────────────────────────────────────────────────────────────────────────────────────
       public static USERS Create_USERS ( string sUSERS_ID  ){
    DataTable dt=SearchByUSERS_ID(sUSERS_ID) ;
    if(dt!=null && dt.Rows.Count>0) 
      return new USERS(dt,0);
      return null;
}
//───────────────────────────────────────────────────────────────────────────────────────
   private static string s_Select()
    {
   return " SELECT T.* FROM USERS AS T";
    }
//───────────────────────────────────────────────────────────────────────────────────────
 public USERS( DataTable table,int pos)
{
         this.USERS_ID= table.Rows[pos]["USERS_ID"].ToString();
         this.USERS_NAME= table.Rows[pos]["USERS_NAME"].ToString();
         this.USERS_PASS= table.Rows[pos]["USERS_PASS"].ToString();
         this.FULL_NAME= table.Rows[pos]["FULL_NAME"].ToString();
         this.ADDRESS= table.Rows[pos]["ADDRESS"].ToString();
         this.PHONE= table.Rows[pos]["PHONE"].ToString();
         this.USER_GROUP_ID= table.Rows[pos]["USER_GROUP_ID"].ToString();
         this.LAST_ACCESS= table.Rows[pos]["LAST_ACCESS"].ToString();
         this.IS_CHANGE_PASS= table.Rows[pos]["IS_CHANGE_PASS"].ToString();
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByUSERS_ID(string sUSERS_ID)
{
          string sqlSelect= s_Select()+ " WHERE USERS_ID  ="+ sUSERS_ID + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByUSERS_ID(string sUSERS_ID,string sMatch)
{
          string sqlSelect= s_Select()+ " WHERE USERS_ID"+ sMatch +sUSERS_ID + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByUSERS_NAME(string sUSERS_NAME)
{
          string sqlSelect= s_Select()+ " WHERE USERS_NAME  Like N'%"+ sUSERS_NAME + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByUSERS_PASS(string sUSERS_PASS)
{
          string sqlSelect= s_Select()+ " WHERE USERS_PASS  Like N'%"+ sUSERS_PASS + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByFULL_NAME(string sFULL_NAME)
{
          string sqlSelect= s_Select()+ " WHERE FULL_NAME  Like N'%"+ sFULL_NAME + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByADDRESS(string sADDRESS)
{
          string sqlSelect= s_Select()+ " WHERE ADDRESS  Like N'%"+ sADDRESS + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByPHONE(string sPHONE)
{
          string sqlSelect= s_Select()+ " WHERE PHONE  Like N'%"+ sPHONE + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByUSER_GROUP_ID(string sUSER_GROUP_ID)
{
          string sqlSelect= s_Select()+ " WHERE USER_GROUP_ID  ="+ sUSER_GROUP_ID + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByUSER_GROUP_ID(string sUSER_GROUP_ID,string sMatch)
{
          string sqlSelect= s_Select()+ " WHERE USER_GROUP_ID"+ sMatch +sUSER_GROUP_ID + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByLAST_ACCESS(string sLAST_ACCESS)
{
          string sqlSelect= s_Select()+ " WHERE LAST_ACCESS  ="+ sLAST_ACCESS + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByLAST_ACCESS(string sLAST_ACCESS,string sMatch)
{
          string sqlSelect= s_Select()+ " WHERE LAST_ACCESS"+ sMatch +sLAST_ACCESS + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByIS_CHANGE_PASS(string sIS_CHANGE_PASS)
{
          string sqlSelect= s_Select()+ " WHERE IS_CHANGE_PASS  Like N'%"+ sIS_CHANGE_PASS + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable Search( string sUSERS_ID
            , string sUSERS_NAME
            , string sUSERS_PASS
            , string sFULL_NAME
            , string sADDRESS
            , string sPHONE
            , string sUSER_GROUP_ID
            , string sLAST_ACCESS
            , string sIS_CHANGE_PASS
            )
 {
       string sqlselect=s_Select() + " WHERE" ;
      if (sUSERS_ID!=null && sUSERS_ID!="") 
            sqlselect +=" AND USERS_ID =" + sUSERS_ID ;
      if (sUSERS_NAME!=null && sUSERS_NAME!="") 
            sqlselect +=" AND USERS_NAME LIKE N'%" + sUSERS_NAME +"%'" ;
      if (sUSERS_PASS!=null && sUSERS_PASS!="") 
            sqlselect +=" AND USERS_PASS LIKE N'%" + sUSERS_PASS +"%'" ;
      if (sFULL_NAME!=null && sFULL_NAME!="") 
            sqlselect +=" AND FULL_NAME LIKE N'%" + sFULL_NAME +"%'" ;
      if (sADDRESS!=null && sADDRESS!="") 
            sqlselect +=" AND ADDRESS LIKE N'%" + sADDRESS +"%'" ;
      if (sPHONE!=null && sPHONE!="") 
            sqlselect +=" AND PHONE LIKE N'%" + sPHONE +"%'" ;
      if (sUSER_GROUP_ID!=null && sUSER_GROUP_ID!="") 
            sqlselect +=" AND USER_GROUP_ID =" + sUSER_GROUP_ID ;
      if (sLAST_ACCESS!=null && sLAST_ACCESS!="") 
            sqlselect +=" AND LAST_ACCESS LIKE '%" + sLAST_ACCESS +"%'" ;
      if (sIS_CHANGE_PASS!=null && sIS_CHANGE_PASS!="") 
            sqlselect +=" AND IS_CHANGE_PASS LIKE N'%" + sIS_CHANGE_PASS +"%'" ;
   sqlselect=sqlselect.Replace("WHERE AND","WHERE");
   int n=sqlselect.IndexOf("WHERE");
   if(n==sqlselect.Length -5) sqlselect=sqlselect.Remove(n,5) ;
   return GetTable(sqlselect,sTableName);
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static USERS Insert_Object(
string  sUSERS_NAME
            ,string  sUSERS_PASS
            ,string  sFULL_NAME
            ,string  sADDRESS
            ,string  sPHONE
            ,string  sUSER_GROUP_ID
            ,string  sLAST_ACCESS
            ,string  sIS_CHANGE_PASS
            ) 
 { 
              string tem_sUSERS_NAME=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sUSERS_NAME,"varchar");
              string tem_sUSERS_PASS=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sUSERS_PASS,"char");
              string tem_sFULL_NAME=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sFULL_NAME,"nvarchar");
              string tem_sADDRESS=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sADDRESS,"nvarchar");
              string tem_sPHONE=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sPHONE,"nvarchar");
              string tem_sUSER_GROUP_ID=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sUSER_GROUP_ID,"int");
              string tem_sLAST_ACCESS=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sLAST_ACCESS,"datetime");
              string tem_sIS_CHANGE_PASS=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sIS_CHANGE_PASS,"nchar");

             string sqlSave=" INSERT INTO USERS("+
                   "USERS_NAME," 
        +                   "USERS_PASS," 
        +                   "FULL_NAME," 
        +                   "ADDRESS," 
        +                   "PHONE," 
        +                   "USER_GROUP_ID," 
        +                   "LAST_ACCESS," 
        +                   "IS_CHANGE_PASS) VALUES("
 +tem_sUSERS_NAME+","
 +tem_sUSERS_PASS+","
 +tem_sFULL_NAME+","
 +tem_sADDRESS+","
 +tem_sPHONE+","
 +tem_sUSER_GROUP_ID+","
 +tem_sLAST_ACCESS+","
 +tem_sIS_CHANGE_PASS +")";
             bool OK = Exec(sqlSave)>=1?true:false;
           if (OK) 
           { 
          USERS newUSERS= new USERS();
                 newUSERS.USERS_ID=GetTable( " SELECT TOP 1 USERS_ID FROM USERS ORDER BY USERS_ID DESC ").Rows[0][0].ToString();
              newUSERS.USERS_NAME=sUSERS_NAME;
              newUSERS.USERS_PASS=sUSERS_PASS;
              newUSERS.FULL_NAME=sFULL_NAME;
              newUSERS.ADDRESS=sADDRESS;
              newUSERS.PHONE=sPHONE;
              newUSERS.USER_GROUP_ID=sUSER_GROUP_ID;
              newUSERS.LAST_ACCESS=sLAST_ACCESS;
              newUSERS.IS_CHANGE_PASS=sIS_CHANGE_PASS;
            return newUSERS; 
           } 
           else return null ;
}
//───────────────────────────────────────────────────────────────────────────────────────
public bool  Save_Object(string sUSERS_NAME
                ,string sUSERS_PASS
                ,string sFULL_NAME
                ,string sADDRESS
                ,string sPHONE
                ,string sUSER_GROUP_ID
                ,string sLAST_ACCESS
                ,string sIS_CHANGE_PASS
                ) 
 { 
              string tem_sUSERS_NAME=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sUSERS_NAME,"varchar");
              string tem_sUSERS_PASS=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sUSERS_PASS,"char");
              string tem_sFULL_NAME=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sFULL_NAME,"nvarchar");
              string tem_sADDRESS=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sADDRESS,"nvarchar");
              string tem_sPHONE=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sPHONE,"nvarchar");
              string tem_sUSER_GROUP_ID=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sUSER_GROUP_ID,"int");
              string tem_sLAST_ACCESS=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sLAST_ACCESS,"datetime");
              string tem_sIS_CHANGE_PASS=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sIS_CHANGE_PASS,"nchar");

 string sqlSave=" UPDATE USERS SET "+"USERS_NAME ="+tem_sUSERS_NAME+","
 +"USERS_PASS ="+tem_sUSERS_PASS+","
 +"FULL_NAME ="+tem_sFULL_NAME+","
 +"ADDRESS ="+tem_sADDRESS+","
 +"PHONE ="+tem_sPHONE+","
 +"USER_GROUP_ID ="+tem_sUSER_GROUP_ID+","
 +"LAST_ACCESS ="+tem_sLAST_ACCESS+","
 +"IS_CHANGE_PASS ="+tem_sIS_CHANGE_PASS+" WHERE USERS_ID="+MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(this.USERS_ID,"int identity");;
              bool OK = Exec(sqlSave)>=1?true:false;
           if (OK) 
           { 
                this.USERS_NAME=sUSERS_NAME;
                this.USERS_PASS=sUSERS_PASS;
                this.FULL_NAME=sFULL_NAME;
                this.ADDRESS=sADDRESS;
                this.PHONE=sPHONE;
                this.USER_GROUP_ID=sUSER_GROUP_ID;
                this.LAST_ACCESS=sLAST_ACCESS;
                this.IS_CHANGE_PASS=sIS_CHANGE_PASS;
           } 
 return OK;  }
//───────────────────────────────────────────────────────────────────────────────────────
 #region Update DataColumn  
 public bool Update_USERS_ID(string sUSERS_ID)
{
    string sqlSave= " UPDATE USERS SET USERS_ID='"+ sUSERS_ID+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.USERS_ID=sUSERS_ID;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_USERS_NAME(string sUSERS_NAME)
{
    string sqlSave= " UPDATE USERS SET USERS_NAME='N"+ sUSERS_NAME+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.USERS_NAME=sUSERS_NAME;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_USERS_PASS(string sUSERS_PASS)
{
    string sqlSave= " UPDATE USERS SET USERS_PASS='N"+ sUSERS_PASS+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.USERS_PASS=sUSERS_PASS;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_FULL_NAME(string sFULL_NAME)
{
    string sqlSave= " UPDATE USERS SET FULL_NAME='N"+ sFULL_NAME+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.FULL_NAME=sFULL_NAME;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_ADDRESS(string sADDRESS)
{
    string sqlSave= " UPDATE USERS SET ADDRESS='N"+ sADDRESS+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.ADDRESS=sADDRESS;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_PHONE(string sPHONE)
{
    string sqlSave= " UPDATE USERS SET PHONE='N"+ sPHONE+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.PHONE=sPHONE;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_USER_GROUP_ID(string sUSER_GROUP_ID)
{
    string sqlSave= " UPDATE USERS SET USER_GROUP_ID='"+ sUSER_GROUP_ID+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.USER_GROUP_ID=sUSER_GROUP_ID;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_LAST_ACCESS(string sLAST_ACCESS)
{
    string sqlSave= " UPDATE USERS SET LAST_ACCESS='"+ sLAST_ACCESS+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.LAST_ACCESS=sLAST_ACCESS;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_IS_CHANGE_PASS(string sIS_CHANGE_PASS)
{
    string sqlSave= " UPDATE USERS SET IS_CHANGE_PASS='N"+ sIS_CHANGE_PASS+ "' WHERE USERS_ID='"+ this.USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.IS_CHANGE_PASS=sIS_CHANGE_PASS;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 #endregion
 #region Update DataColumn  Static 
 public static bool Update_USERS_NAME(string sUSERS_NAME,string s_USERS_ID)
{
  string sqlSave= " UPDATE USERS SET USERS_NAME='N"+sUSERS_NAME+"' WHERE USERS_ID='"+ s_USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_USERS_PASS(string sUSERS_PASS,string s_USERS_ID)
{
  string sqlSave= " UPDATE USERS SET USERS_PASS='N"+sUSERS_PASS+"' WHERE USERS_ID='"+ s_USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_FULL_NAME(string sFULL_NAME,string s_USERS_ID)
{
  string sqlSave= " UPDATE USERS SET FULL_NAME='N"+sFULL_NAME+"' WHERE USERS_ID='"+ s_USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_ADDRESS(string sADDRESS,string s_USERS_ID)
{
  string sqlSave= " UPDATE USERS SET ADDRESS='N"+sADDRESS+"' WHERE USERS_ID='"+ s_USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_PHONE(string sPHONE,string s_USERS_ID)
{
  string sqlSave= " UPDATE USERS SET PHONE='N"+sPHONE+"' WHERE USERS_ID='"+ s_USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_USER_GROUP_ID(string sUSER_GROUP_ID,string s_USERS_ID)
{
  string sqlSave= " UPDATE USERS SET USER_GROUP_ID='"+sUSER_GROUP_ID+"' WHERE USERS_ID='"+ s_USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_LAST_ACCESS(string sLAST_ACCESS,string s_USERS_ID)
{
  string sqlSave= " UPDATE USERS SET LAST_ACCESS='"+sLAST_ACCESS+"' WHERE USERS_ID='"+ s_USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_IS_CHANGE_PASS(string sIS_CHANGE_PASS,string s_USERS_ID)
{
  string sqlSave= " UPDATE USERS SET IS_CHANGE_PASS='N"+sIS_CHANGE_PASS+"' WHERE USERS_ID='"+ s_USERS_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
#endregion
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable GetTableAll() 
 {
       return  GetTableAll(null, null);
 }
public static DataTable GetTableAll(string sWhere, params string[] orderFields)
{
   string sqlSelect = " SELECT * FROM USERS";
   if (!string.IsNullOrEmpty(sWhere))
      sqlSelect += " where " + sWhere; 
   string order = "";
   if (orderFields != null && orderFields.Length > 0)
     order = string.Join(",", orderFields);
   if (order != "")
      sqlSelect += " ORDER BY " + order;
   return GetTable(sqlSelect,sTableName);
}
//───────────────────────────────────────────────────────────────────────────────────────
//───────────────────────────────────────────────────────────────────────────────────────
public static DataTable GetTableFields(string sWhere, string[] orderFields, params string[] fields)
{
 string field = "";
 if (fields != null && fields.Length > 0)
    field = string.Join(",", fields);
 else field = "*";
 string sqlSelect = string.Format(" SELECT {0} FROM {1} ", field, "USERS");
 if (!string.IsNullOrEmpty(sWhere))
    sqlSelect += " where " + sWhere;
 string order = "";
 if (orderFields != null && orderFields.Length > 0)
    order = string.Join(",", orderFields);
 if (order != "")
    sqlSelect += " ORDER BY " + order;
 return GetTable(sqlSelect,sTableName);
 }
 public static DataTable GetTableFields(params string[] fields)
 {
    return GetTableFields(null, null, fields);
 }
 public static DataTable GetTableFields(string[] orderFields, params string[] fields)
 {
    return GetTableFields(null, orderFields, fields);
 }
//───────────────────────────────────────────────────────────────────────────────────────
   private static DataTable dt_USERS;
   public static bool Change_dt_USERS = true;
   public static bool AllowAutoChange = true;
   public static DataTable get_USERS()
   {
   if (dt_USERS == null || Change_dt_USERS == true)
     {
   dt_USERS = GetTableAll();
         Change_dt_USERS = true && AllowAutoChange ;
     }
     return dt_USERS;
   }
   //───────────────────────────────────────────────────────────────────────────────────────
}  
 } 
